package com.lzx.iteam.widget;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.TextPaint;
import android.text.style.ClickableSpan;
import android.view.View;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.TalkListActivity;
import com.lzx.iteam.util.Constants;

import java.util.Map;

public class TextViewSpan<T> extends ClickableSpan{
		private String clickString;
		private Context mContext;
		private int selectClick;
		private T votePerson;
		private int mColor;

		
		public TextViewSpan(String clickString,Context context,int selectClick,int mColor) {
			this.clickString = clickString;
			this.mContext=context;
			this.selectClick=selectClick;
			this.mColor = mColor;
		}

		
		/**
		 * 设置点赞人的信息
		 * @param t
		 */
		public void setInfo(T t){
			votePerson=t;
		}
		
		@Override
		public void updateDrawState(TextPaint ds) {
			if (mColor == 1 ){
				ds.setColor(mContext.getResources().getColor(
						R.color.event_reg_color_1));
			} else if (mColor == 2){
				ds.setColor(mContext.getResources().getColor(
						R.color.event_reg_color_2));
			} else if (mColor == 3){
				ds.setColor(mContext.getResources().getColor(
						R.color.event_reg_color_3));
			}else{
				ds.setColor(mContext.getResources().getColor(
						R.color.talk_item_comment_name));
			}
			ds.setUnderlineText(false); // 去掉下划线
		}

		@Override
		public void onClick(View widget) {
			switch (selectClick) {
			case 0://打开个人主界面
				avoidHintColor(widget);
				Map<String,String> person = (Map<String,String>)votePerson;
//				Toast.makeText(mContext, person.get(Constants.TALK_USER_NAME),
//						Toast.LENGTH_SHORT).show();
				Intent intent1 = new Intent(mContext, TalkListActivity.class);
				intent1.setAction(TalkListActivity.OTHER_PERSONAL_SPACE);
				intent1.putExtra("set_user_id", person.get(Constants.TALK_USER_ID));
				mContext.startActivity(intent1);
				((Activity)mContext).finish();
				break;
			case 1:
				Map<String,String> reply = (Map<String,String>)votePerson;
//				Toast.makeText(mContext, reply.get(Constants.TALK_REPLY_NAME),
//						Toast.LENGTH_SHORT).show();
				break;
			default:
				break;
			}
			
		}

	private void avoidHintColor(View view) {
		if (view instanceof TextView)
			((TextView) view).setHighlightColor(mContext.getResources().getColor(R.color.event_content_copy));
	}

}
